﻿<#import "../../_layout.ftl" as layout>
${Html.s("pagetitle","流程详情")}
<@layout._layout>
<style>

</style>

<script>
	//获取url中的参数
    function getUrlParam(name) {
    	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]); return null; //返回参数值
    }
    $(document).ready(function(){
    	var modeid=getUrlParam("modeid");
    	if(!modeid || typeof(modeid)=="undefined" || modeid=="")
		{
			alert("请选择流程");
			window.location.href="create?modeid="+id;
		}
		
		$.ajax({
			url:'/user/flow/mode',
			type:"POST",
			dataType:"json",
			data:{
				"modeid":modeid
			},
			success:function(datas){				
				$("#flowForm").attr("srcdoc",datas.data.pcForm);
			},
			error:function(){
				alert("流程异常，请联系管理员");
			}
		});
		$("#submitFlow").click(function(){//提交流程
			var data = new Array(); 
			//var arry = $("#flowForm").contents().find("form").children();
			//$("#flowForm input,select,textarea").each(function(index){
			$("#flowForm").contents().find("form").find("input,select,textarea").each(function(index){
				var input=new Object();			
				input.id=$(this).attr('id');
				input.name=$(this).attr('name');
				input.key=$(this).attr('name');
			    input.value=$(this).val();
			    input.type=$(this).attr('type');
			    input.hidden=$(this).attr('hidden');
			    if (input.type=='textarea'){
	                  input.value=$(this).text();
	              }else if (input.type=='combobox'){
	                  input.value=$(this).combobox('getValue');
	              }else if (input.type=='checkbox'){
	                  if ($(this).is(':checked')) 
							input.value=input.attr('xtext');
	              }else if (input.type!='button'){
		              input.value=$(this).val(); 
	              }	     		
				data.push(input);
			
			});			
			$.ajax({
				url:"saveflow",
				type:"POST",
				dataType:"json",
				data:{
					modeid:getUrlParam("modeid"),
					form:JSON.stringify(data),
					userNo:	${user.userno}				
				},
				success:function(datas){						
					window.location.href="lunched_list";
				},
				error:function(e){
					alert(JSON.stringify(e));
				}
			})
		
	});
	});
	
	function setIframeHeight(iframe) {
		if (iframe) {
			var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
			if (iframeWin.document.body) {
				iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
			}
		}
	};

	//window.ondebugger = function () {setIframeHeight(document.getElementById('flowForm'));};
    function show_detail(){
	}
</script>
<div class="head">
    <div class="title">
       发起流程 ${Html.help("发起流程")}
    </div>
</div>
<iframe id="flowForm" style="width:100%; padding-bottom:10px;" src="" frameborder="0" scrolling="no" noresize="false" height="150">
</iframe>
<div style="text-align:center;">
	<button id="submitFlow" class="btn1">保存</button>
</div>"
</@layout._layout>